<?php
/*  LOAD SYSTEM FUNCTIONS MANUALLY
    ============================================================================================================== */
	require_once( "functions/inc.database.php" );
	require_once( "functions/inc.getData.php" );
	require_once( "functions/inc.pageSetup.php" );
	
	# init session
	session_start();
	
	page_header( "Wayne Schlegel Inc. | Account activation", false );
?>

<?php
	$sql = "SELECT * FROM userData WHERE activationId = '" . $_GET['uid'] . "'";
	$res = mysql_query( $sql );
	if( mysql_num_rows( $res ) == 0 ) {
		echo "<p class=\"error\">Sorry, but there's something wrong with the activation. Please ensure, that you find the whole link in your URL-field.</p>";
	} else {
		// check if username and uniqueId fit
		$row = mysql_fetch_array( $res );
		if( $row['username'] == base64_decode( $_GET['usr'] ) ) {
			$now       = date( "Y-m-d H:i:s" );
			$sql_update = "UPDATE userData SET hasBeenActivated = 1, timeOfActivation = '" . $now . "', lastWriteAccess = '" . $now . "'  WHERE id = " . $row['id'];
			$res_update = mysql_query( $sql_update );
			if( $res_update ) {
				echo "Your account is now activated. You can <a href=\"loginForm.php\">login now</a> and enjoy our webservice.";
			} else {
				echo "Something went wrong while activating your account. " . mysql_error();
			}
		} else {
			echo "Something went wrong while activating your account. " . mysql_error();
		}
	}
?>